<?php
/**
 * User: aka
 * Time: 19:50
 */

namespace app\write\controller;

use app\validate\clanActivity\SendClanActivity;
use think\facade\Session;
use think\Request;

class ClanActivity
{
    private $userId;
    private $views;
    private $deleteState;

    public function __construct()
    {
        $this->userId = Session::get('user_info.id');
        $this->views = 1;
        $this->deleteState = 0;
    }

    public function __destruct()
    {
        unset(
            $this->userId,
            $this->views,
            $this->deleteState
        );
    }

    public function sendClanActivity(Request $request)
    {
        $validate = new SendClanActivity();
        if (!$validate->check($request->param())) {
            return json($validate->getError());
        }else{
            \app\tenno\model\ClanActivity::create([
                'title' => $request->param('title'),
                'activity_time' => $request->param('activity_time'),
                'content' => $request->param('content'),
                'page_views' => $this->views,
                'uid' => $this->userId,
                'delete_state' => $this->deleteState
            ]);
            return json([
                'state' => 200
            ]);
        }
    }
}